package com.sunday.authorization.security.tools.userdetails;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.Tolerate;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;

/**
 * @Description: 当前用户信息
 */
@Slf4j
@Data
@Builder
public class UserInfo implements Serializable {

    public static final String HTTP_HEADER_AUTH_TOKEN_INFO = "tokenInfo";

    public static final Gson DEFAULT = new GsonBuilder()
            .disableHtmlEscaping()//gson会默认将特殊字符转化成unicode编码
            .create();

    //用户ID
    private Long id;

    //用户账户
    private String username;

    // 权限总和
    private long[] permissionsSum;

    @Tolerate
    public UserInfo() {
    }

    public UserInfo(Long id, String username, long[] permissionsSum) {
        this.id = id;
        this.username = username;
        this.permissionsSum = permissionsSum;
    }

    @Override
    public String toString() {
        return DEFAULT.toJson(this);
    }

}
